from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings

from config.embeddings import embed_model_local_bge_small
from config.llm import deepseek_llm
from tool.file_tool import  getRootPath
# 加载指定目录下的文件
documents = SimpleDirectoryReader('../data').load_data()

# 设置LLM和Embedding模型
Settings.llm = deepseek_llm()
Settings.embed_model = embed_model_local_bge_small()

# 构建向量索引
vector_index = VectorStoreIndex.from_documents(documents)

#获取根目录
rootPath = getRootPath()
print("rootPath：",rootPath)
# 保存索引到磁盘
vector_index.storage_context.persist(rootPath + '/store/vector_index')